import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  int _selectedIndex = 0;
  String _courseInfo = '课程数信息11111';
  String _leaveInfo = '课程数信息11111';
  TextEditingController _courseInfoController = TextEditingController();
  TextEditingController _leaveInfoController = TextEditingController();
  bool _showCustomPage = false; // 控制自定义页面的显示与隐藏
  int _counter1 = 0;
  int _counter2 = 0;
  int _counter3 = 0;
  int _counter4 = 0;

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
      if (_selectedIndex == 0) {
        _courseInfo = '课程数信息11111';
        _leaveInfo = '课程数信息11111';
      } else if (_selectedIndex == 1) {
        _showCustomPage = true; // 点击抽签数按钮时显示自定义页面
      } else if (_selectedIndex == 2) {
        _courseInfo = '请假数信息222222';
        _leaveInfo = '请假数信息222222';
        _showCustomPage = false; // 点击请假数按钮时隐藏自定义页面
      }
      _courseInfoController.text = _courseInfo;
      _leaveInfoController.text = _leaveInfo;
    });
  }

  @override
  void initState() {
    super.initState();
    _courseInfoController.text = _courseInfo;
    _leaveInfoController.text = _leaveInfo;
  }

  @override
  void dispose() {
    _courseInfoController.dispose();
    _leaveInfoController.dispose();
    super.dispose();
  }

  void _decrementCounter1() {
    setState(() {
      _counter1--;
    });
  }

  void _incrementCounter1() {
    setState(() {
      _counter1++;
    });
  }

  void _decrementCounter2() {
    setState(() {
      _counter2--;
    });
  }

  void _incrementCounter2() {
    setState(() {
      _counter2++;
    });
  }

  void _decrementCounter3() {
    setState(() {
      _counter3--;
    });
  }

  void _incrementCounter3() {
    setState(() {
      _counter3++;
    });
  }

  void _decrementCounter4() {
    setState(() {
      _counter4--;
    });
  }

  void _incrementCounter4() {
    setState(() {
      _counter4++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Profile Page'),
        ),
        body: Column(
          children: [
            Container(
              color: Colors.purple,
              padding: EdgeInsets.all(16),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  CircleAvatar(
                    radius: 40,
                    backgroundColor: Colors.blue,
                    child: Icon(
                      Icons.person,
                      size: 40,
                      color: Colors.white,
                    ),
                  ),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(
                          '名字',
                          style: TextStyle(
                            fontSize: 22,
                            fontWeight: FontWeight.bold,
                            color: Colors.white,
                          ),
                        ),
                        Text(
                          '邮箱',
                          style: TextStyle(
                            fontSize: 22,
                            fontWeight: FontWeight.bold,
                            color: Colors.white,
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              color: Colors.white,
              padding: EdgeInsets.all(16),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  BottomNavigationBar(
                    currentIndex: _selectedIndex,
                    onTap: _onItemTapped,
                    items: <BottomNavigationBarItem>[
                      BottomNavigationBarItem(
                        icon: Icon(null),
                        label: '课程数',
                      ),
                      BottomNavigationBarItem(
                        icon: Icon(null),
                        label: '签到数',
                      ),
                      BottomNavigationBarItem(
                        icon: Icon(null),
                        label: '请假数',
                      ),
                    ],
                    selectedItemColor:
                    _selectedIndex == 0 ? Colors.blue : null,
                  ),
                  SizedBox(height: 20),
                  Visibility(
                    visible: !_showCustomPage,
                    child: Container(
                      height: 80,
                      decoration: BoxDecoration(
                        border: Border.all(
                          color: Colors.lightGreen,
                          width: 2.0,
                        ),
                      ),
                      child: TextFormField(
                        enabled: false,
                        textAlign: TextAlign.center,
                        controller: _courseInfoController,
                      ),
                    ),
                  ),
                  SizedBox(height: 16),
                  Visibility(
                    visible: !_showCustomPage,
                    child: Container(
                      height: 80,
                      decoration: BoxDecoration(
                        border: Border.all(
                          color: Colors.lightGreen,
                          width: 2.0,
                        ),
                      ),
                      child: TextFormField(
                        enabled: false,
                        textAlign: TextAlign.center,
                        controller: _leaveInfoController,
                      ),
                    ),
                  ),
                  if (_selectedIndex == 1 && _showCustomPage) ...[
                    Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        IconButton(
                          icon: Icon(Icons.remove),
                          onPressed: _decrementCounter1,
                        ),
                        Container(
                          width: 30,
                          height: 30,
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: Colors.black,
                              width: 2.0,
                            ),
                          ),
                          child: Center(
                            child: Text(
                              '$_counter1',
                              style: TextStyle(
                                fontSize: 14,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ),
                        ),
                        IconButton(
                          icon: Icon(Icons.add),
                          onPressed: _incrementCounter1,
                        ),
                        ElevatedButton(
                          onPressed: () {
                            // TODO: Add your logic here
                          },
                          child: Text('确认'),
                        ),
                      ],
                    ),
                    SizedBox(height: 40),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        Container(
                          width: 60,
                          height: 60,
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            color: Colors.blue,
                          ),
                        ),
                        Container(
                          width: 60,
                          height: 60,
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            color: Colors.green,
                          ),
                        ),
                        Container(
                          width: 60,
                          height: 60,
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            color: Colors.red,
                          ),
                        ),
                      ],
                    ),
                    SizedBox(height: 10),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        IconButton(
                          icon: Icon(Icons.remove),
                          onPressed: _decrementCounter2,
                        ),
                        Container(
                          width: 20,
                          height: 20,
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: Colors.black,
                              width: 2.0,
                            ),
                          ),
                          child: Center(
                            child: Text(
                              '$_counter2',
                              style: TextStyle(
                                fontSize: 14,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ),
                        ),
                        IconButton(
                          icon: Icon(Icons.add),
                          onPressed: _incrementCounter2,
                        ),
                        IconButton(
                          icon: Icon(Icons.remove),
                          onPressed: _decrementCounter3,
                        ),
                        Container(
                          width: 20,
                          height: 20,
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: Colors.black,
                              width: 2.0,
                            ),
                          ),
                          child: Center(
                            child: Text(
                              '$_counter3',
                              style: TextStyle(
                                fontSize: 14,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ),
                        ),
                        IconButton(
                          icon: Icon(Icons.add),
                          onPressed: _incrementCounter3,
                        ),
                        IconButton(
                          icon: Icon(Icons.remove),
                          onPressed: _decrementCounter4,
                        ),
                        Container(
                          width: 20,
                          height: 20,
                          decoration: BoxDecoration(
                            border: Border.all(
                              color: Colors.black,
                              width: 2.0,
                            ),
                          ),
                          child: Center(
                            child: Text(
                              '$_counter4',
                              style: TextStyle(
                                fontSize: 14,
                                fontWeight: FontWeight.bold,
                              ),
                            ),
                          ),
                        ),
                        IconButton(
                          icon: Icon(Icons.add),
                          onPressed: _incrementCounter4,
                        ),
                      ],
                    ),
                    SizedBox(height: 80),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                      children: [
                        ElevatedButton(
                          onPressed: () {
                            // TODO: Add your logic here
                          },
                          child: Text('加分'),
                        ),
                        ElevatedButton(
                          onPressed: () {
                            // TODO: Add your logic here
                          },
                          child: Text('确认'),
                        ),
                      ],
                    ),
                  ],
                ],
              ),
            ),
          ],
        ),
        bottomNavigationBar: BottomNavigationBar(
          currentIndex: _selectedIndex,
          onTap: _onItemTapped,
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.message),
              label: '课表',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.home),
              label: '签到',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.person),
              label: '我的',
            ),
          ],
          selectedItemColor: Colors.green,
        ),
      ),
    );
  }
}